package com.huawei.statistics.service.impl.index;

import com.huawei.statistics.pojo.index.Banner;
import com.huawei.statistics.service.impl.common.BaseServiceImpl;
import com.huawei.statistics.service.index.BannerService;
import com.huawei.statistics.vo.common.HttpResult;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class BannerServiceImpl extends BaseServiceImpl implements BannerService{

	@Override
	public Banner findBannerById(Long id) {

		return getEntityById(id,Banner.class);
	}

	
	
	@Override
	public HttpResult getBannerById(Long id) {
		
		return new HttpResult(HttpResult.OK,getEntityById(id, Banner.class));
	}


	@Override
	public HttpResult addBanner(Banner banner) {

		Long id = addEntityReturnId(banner);
		banner.setId(id);
		return new HttpResult(HttpResult.OK,banner);
	}


	@Override
	public HttpResult delBanner(Long id) {

		Banner banner = findBannerById(id);
		if(banner != null){
			banner.setDel(true);
		}
		return new HttpResult(HttpResult.OK,update(banner));
	}


	@Override
	public HttpResult update(Banner banner) {
		
		return new HttpResult(HttpResult.OK,updateEntityValues(banner));
	}

	@Override
	public List<Banner> getBannerList(int type) {
		Map<String,	Object> map = new HashMap<String,Object>();
		map.put("del",false);
		if(type != 0){
			map.put("type",type);
		}
		return getEntitiesBySort(Banner.class,map,"sort",true);
	}
}
